<template>
  <van-icon color="#777"
  :name="likeThumbs===1?'good-job':'good-job-o' "
  @click="changeThumbs"
  :class="likeThumbs===1?'active':''"
  />
</template>

<script>
import { getLiking, delLiking } from '@/api/article'
export default {
  data () {
    return {
    }
  },
  props: {
    likeThumbs: { // 点赞情况 1喜欢 -1不喜欢
      type: Number,
      required: true
    },
    value: { // 文章id
      type: [Number, String, Object],
      required: true
    }
  },
  components: {},
  created () {},
  computed: {},
  methods: {
    async changeThumbs () {
      this.$toast.loading({
        duration: 0,
        message: '加载中...',
        forbidClick: true
      })
      try {
        if (this.likeThumbs === 1) { // 已经点赞
          await delLiking(this.value)
          this.$emit('update:like-thumbs', -1)
          this.$toast.success('取消点赞')
        } else { // 未点赞
          await getLiking(this.value) // like-thumbs
          this.$emit('update:like-thumbs', 1)
          this.$toast.success('点赞成功')
        }
      } catch (err) {
        this.$toast.fail('点赞失败，请稍后重试！')
        console.log('点赞请求失败')
      }
    }
  }
}
</script>

<style lang='less' scoped>
.active{
    color:orange !important;
}
</style>
